package com.javacoo.xservice.base.support.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import com.javacoo.xkernel.spi.ExtensionLoader;
import com.javacoo.xservice.base.support.security.config.SecurityConfig;

import lombok.extern.slf4j.Slf4j;

/**
 * 安全接口工厂
 * <li></li>
 *
 * @author: duanyong@jccfc.com
 * @since: 2021/4/15 18:46
 */
@Slf4j
@Component
@ConditionalOnBean(SecurityConfig.class)
public class SecurityFactory {
    /** 安全配置 */
    @Autowired
    private SecurityConfig securityConfig;

    @Bean
    public SignService createSignService() {
        log.info("初始化安全接口,实现类名称:{}",securityConfig.getImpl());
        SecurityHolder.signService = ExtensionLoader.getExtensionLoader(SignService.class).getExtension(securityConfig.getImpl());
        log.info("初始化安全接口成功,实现类:{}",SecurityHolder.signService);
        return SecurityHolder.signService;
    }
}
